package keyboard;

import java.util.HashMap;
import java.util.HashSet;

class GroupCostCalculatorUsingCursorMouse extends GroupCostCalculator {
	static final float MOVING_SPEED = 1f;
	static final float SELECT_DWELL_TIME = 0.36f;
	static final float SELECT_MOVE_TIME = 0.55f;
	static final float TURNING_PAGE_TIME = 1.89f;
	
	public GroupCostCalculatorUsingCursorMouse(Keyboard keyboard, HashSet<Character> keysGroup, HashMap<Character, Float> keysValue, Position lastPosition) {
		super(keyboard, keysGroup, keysValue, lastPosition);
	}

	@Override
	public float GetTheCostOfPriority(int priority) {
		/*float scanCost = 0f;
		int pos = (priority - 1) % 5 + 1;
		int page = (priority - 1) / 5 + 1;
		if (priority <= 5) {
			Position confirmCentre = keyboard.GetSelectorCentrePosition(pos);
			Position confirmSize = keyboard.GetSelectorSize();
			Position confirmPosition = Position.getPressPosition(codeEndPosition, confirmCentre, confirmSize);
			scanCost = Position.EuclidDist(codeEndPosition, confirmPosition);
		} else {
			Position nextCentre = keyboard.GetNextCentrePosition();
			Position nextSize = keyboard.GetSelectorSize();
			Position nextPosition = Position.getPressPosition(codeEndPosition, nextCentre, nextSize);
			Position confirmCentre = keyboard.GetSelectorCentrePosition(pos);
			Position confirmSize = keyboard.GetSelectorSize();
			Position confirmPosition = Position.getPressPosition(nextPosition, confirmCentre, confirmSize);
			scanCost = Position.EuclidDist(codeEndPosition, nextPosition) + Position.EuclidDist(nextPosition, confirmPosition);
			scanCost += (page - 1) * Keyboard.layout[0].length;
		}
		return scanCost;*/
		int pos = (priority - 1) % 5 + 1;
		int page = (priority - 1) / 5 + 1;
		return SELECT_DWELL_TIME + TURNING_PAGE_TIME * (page - 1) + SELECT_MOVE_TIME * (pos / 2);
	}
	
	public float GetMovingCost() {
		Position groupCentre = keyboard.GetGroupCentrePosition(keysGroup);
		Position groupSize = keyboard.GetGroupSize(keysGroup);
		Position moveEndPosition = Position.getPressPosition(lastPosition, groupCentre, groupSize);
		return Position.EuclidDist(lastPosition, moveEndPosition) / MOVING_SPEED;
	}

	@Override
	public float GetExpectedCost() {
		return GetMovingCost() * keyboard.CalnGroupValue(keysGroup, keysValue) + GetSelectingCost();
	}
}
